| Conditions | 2 |
| Paths | 961 |
| Total Lines | 91 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | (function ($, window) { |
||
| 3 | $(function () { |
||
| 4 | |||
| 5 | var |
||
| 6 | nId = null, |
||
| 7 | bStarted = false |
||
| 8 | ; |
||
| 9 | |||
| 10 | function ShowRecaptcha() |
||
| 11 | { |
||
| 12 | if (window.grecaptcha) |
||
| 13 | { |
||
| 14 | if (null === nId) |
||
| 15 | { |
||
| 16 | var |
||
| 17 | oEl = null, |
||
| 18 | oLink = $('.plugin-mark-Login-BottomControlGroup') |
||
| 19 | ; |
||
| 20 | |||
| 21 | if (oLink && oLink[0]) |
||
| 22 | { |
||
| 23 | oEl = $('<div class="controls"></div>'); |
||
| 24 | |||
| 25 | $(oLink[0]).after(oEl); |
||
| 26 | |||
| 27 | nId = window.grecaptcha.render(oEl[0], { |
||
| 28 | 'sitekey': window.rl.pluginSettingsGet('recaptcha', 'public_key'), |
||
| 29 | 'theme': window.rl.pluginSettingsGet('recaptcha', 'theme') |
||
| 30 | }); |
||
| 31 | } |
||
| 32 | } |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | window.__globalShowRecaptcha = ShowRecaptcha; |
||
| 37 | |||
| 38 | function StartRecaptcha() |
||
| 39 | { |
||
| 40 | if (!window.grecaptcha && window.rl) |
||
| 41 | { |
||
| 42 | $.getScript('https://www.google.com/recaptcha/api.js?onload=__globalShowRecaptcha&render=explicit&hl=' + window.rl.settingsGet('Language')); |
||
| 43 | } |
||
| 44 | else |
||
| 45 | { |
||
| 46 | ShowRecaptcha(); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | if (window.rl) |
||
| 51 | { |
||
| 52 | window.rl.addHook('user-login-submit', function (fSubmitResult) { |
||
| 53 | if (null !== nId && !window.grecaptcha.getResponse(nId)) |
||
| 54 | { |
||
| 55 | fSubmitResult(105); |
||
| 56 | } |
||
| 57 | }); |
||
| 58 | |||
| 59 | window.rl.addHook('view-model-on-show', function (sName, oViewModel) { |
||
| 60 | if (!bStarted && oViewModel && |
||
| 61 | ('View:RainLoop:Login' === sName || 'View/App/Login' === sName || 'LoginViewModel' === sName || 'LoginAppView' === sName) && |
||
| 62 | window.rl.pluginSettingsGet('recaptcha', 'show_captcha_on_login')) |
||
| 63 | { |
||
| 64 | bStarted = true; |
||
| 65 | StartRecaptcha(); |
||
| 66 | } |
||
| 67 | }); |
||
| 68 | |||
| 69 | window.rl.addHook('ajax-default-request', function (sAction, oParameters) { |
||
| 70 | if ('Login' === sAction && oParameters && null !== nId && window.grecaptcha) |
||
| 71 | { |
||
| 72 | oParameters['RecaptchaResponse'] = window.grecaptcha.getResponse(nId); |
||
| 73 | } |
||
| 74 | }); |
||
| 75 | |||
| 76 | window.rl.addHook('ajax-default-response', function (sAction, oData, sType) { |
||
| 77 | if ('Login' === sAction) |
||
| 78 | { |
||
| 79 | if (!oData || 'success' !== sType || !oData['Result']) |
||
| 80 | { |
||
| 81 | if (null !== nId && window.grecaptcha) |
||
| 82 | { |
||
| 83 | window.grecaptcha.reset(nId); |
||
| 84 | } |
||
| 85 | else if (oData && oData['Captcha']) |
||
| 86 | { |
||
| 87 | StartRecaptcha(); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | }); |
||
| 92 | } |
||
| 93 | }); |
||
| 94 | |||
| 95 | }($, window)); |